<template>
<div class="app-container">
  <el-form ref="item" label-width="160px">
    <el-row>
      <div class="form-box">
        <div>
          <el-form-item label="用户昵称:">
            {{ form.nickname }}
          </el-form-item>
          <el-form-item label="性别:">
            {{ form.sex || '--' }}
          </el-form-item>
          <el-form-item label="头像:">
            <img v-bind:src="form.headerimg_url" alt="头像">
          </el-form-item>
          <el-form-item label="手机号码:">
            {{ form.user_phone }}
          </el-form-item>
        </div>
        <div>
          <!-- <el-form-item label="当前登录IP:"> -->
            <!-- {{ orderDetail.user_address_id.mobile_phone }} -->
          <!-- </el-form-item> -->
          <!-- <el-form-item label="当前登录设备:"> -->
            <!-- {{ orderDetail.user_address_id.mobile_phone }} -->
          <!-- </el-form-item> -->
          <!-- <el-form-item label="常用城市:"> -->
            <!-- {{ form.address || '--' }} -->
          <!-- </el-form-item> -->
          <el-form-item label="兴趣标签:">
            {{ form.user_select_tag || '--' }}
          </el-form-item>
          <el-form-item label="当前积分:">
            0
          </el-form-item>
          <el-form-item label="上次登录时间:">
            {{ form.lastTime | fomateTime }}
          </el-form-item>
        </div>
      </div>
    </el-row>
  </el-form>
  <div class="title" v-if="busniess.busName">商家信息</div>
  <el-form ref="form" label-width="160px">
    <el-form-item v-if="busniess.busName" label="序号:">
      <span  v-text="busniess.busName"></span>
    </el-form-item>
    <el-form-item v-if="busniess.busName" label="联系人:">
      <span v-text="busniess.busAdress"></span>
    </el-form-item>
    <el-form-item v-if="busniess.busPer" label="联系电话:">
      <span v-text="busniess.busPer"></span>
    </el-form-item>
    <el-form-item v-if="busniess.busTel" label="服务地址:">
      <span v-text="busniess.busTel"></span>
    </el-form-item>
  </el-form>
  <div class="title">服务地址数组</div>
  </br>
  <el-table :data="service" border>
    <el-table-column align="center" prop="id" label="序号">
    </el-table-column>
    <el-table-column align="center" prop="person" label="联系人">
    </el-table-column>
    <el-table-column align="center" prop="tel" label="联系方式">
    </el-table-column>
    <el-table-column align="center" prop="address" label="地址">
    </el-table-column>
  </el-table>
  <div class="block">
    <el-button type="info" @click="back">返回</el-button>
    <el-button class="upload" @click="exportExcel">导出excal
    </el-button>
  </div>
</div>
</template>

<script>
import request from '@/utils/request'
import { formatDate,toUnix,toDate } from '@/utils/index'
import { validateOrderStatus,Excel } from '@/utils/validate'
export function getList(mes) {
  return request({
    url: '/v1/admin/user/userAddress',
    method: 'post',
    data: mes
  })
}
export default {
  data(){
    return{
      form: {},
      service: [],
      busniess: {},
      orderDetail: {},
      tableData: [],
    }
  },
  created: function() {
    const n= JSON.parse(localStorage.getItem('clientMes'))
    console.log(n);
    this.form = {
      nickname: n.nickname,
      sex: n.sex,
      user_phone: n.user_phone,
      headerimg_url: n.headerimg_url,
      user_select_tag: n.user_select_tag.join(),
      lastTime: n.last_login_time
    }
    // console.log(this.$route.query._id);
    const mes = {
      user_id: n._id
    }
    console.log(mes);
    this.getMes(mes)
  },
  methods:{
    getMes(mes) {
      getList(mes).then(res => {
        if (res.code === 200) {
          console.log(res);
          if (res.data.length) {
            res.data.filter(item => {
              const val = {
                id: item._id,
                person: item.user_name,
                tel: item.mobile_phone,
                address: item.address_name,
              }
              this.service.push(val)
            })
          }
        } else {
          this.$message({
            message: res.msg,
            type: 'error'
          });
        }
      }).catch(error => {
        this.$message({
          message: error,
          type: 'error'
        });
      })
    },
    exportExcel() {
      Excel('#out-table')
    },
    back() {
      this.$router.go(-1)
    },
  },
  filters: {
    orderStatus(item) {
      return validateOrderStatus(item)
    },
    fomateTime(time) {
      return time ? formatDate(new Date(time*1000), 'yyyy-MM-dd  hh:mm') : '--'
    },
    pay_type(type) {
      if (type === 1) {
        return '支付宝'
      } else if (type === 2) {
        return '微信'
      } else if (type === 0) {
        return '其他'
      }
    }
  }
}
</script>

<style scoped>
  .title{
    height: 30px;
    line-height: 30px;
    font-weight: bold;
    border-top: 1px solid #d4d4d4;
  }
  .form-box{
    display: flex;
    flex-wrap: wrap;
  }
  .form-box div{
    width: 40%;
  }
  .block{
    display: flex;
    justify-content: space-between;
  }
  .block button{
    margin: 10px;
  }
</style>
